package com.sky.mapper;

import com.sky.entity.SetmealDish;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {
    /**
     * 根据菜品id查询对应的套餐id
     * @param dishIds
     * @return
     */
    List<Long> getSetmealIdsByDishIds(List<Long> dishIds);

    /**
     * 根据套餐ID查询对应套餐信息
     * @param id
     * @return
     */
    @Select("select id, setmeal_id, dish_id, name, price, copies from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> selectBySetMealId(Long id);
    /**
     * 批量插入套餐菜品信息
     * @param setmealDishes
     */
    void insertSetmealDish(List<SetmealDish> setmealDishes);

    /**
     * 根据套餐ID删除套餐菜品信息
     *
     * @param setmealId
     */
    void delete(List<Long> ids);

    /**
     * 根据菜品id有无关联的套餐
     * @param id
     * @return
     */
    @Select("select setmeal_id from setmeal_dish where dish_id = #{id}")
    List<Long> selectSetmealIdByDishId(Long id);

    /**
     * 根据套餐id查询菜品中有无停售菜品
     * @param id
     * @param status
     * @return
     */
    @Select("select count(*) from setmeal_dish sd join dish d on d.id = sd.dish_id where sd.setmeal_id = #{id} and d.status = #{status}")
    Integer selectDishIdBySetmeal(Long id,Integer status);
}
